﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace boe2.irc
{
	public class IrcPrefix
	{
		public String Nick { get; private set; }
		public String User { get; private set; }
		public String Host { get; private set; }
		public Boolean IsGlobal { get; private set; }

		public IrcPrefix(String prefix)
		{
			if (!String.IsNullOrEmpty(prefix))
			{
				Int32 atIndex = prefix.IndexOf("@");
				if (atIndex == -1)
				{
					Host = prefix;
					IsGlobal = true;
					return;
				}
				Host = prefix.Substring(atIndex + 1);
				String nickUser = prefix.Substring(0, atIndex);
				Int32 exclamIndex = nickUser.IndexOf("!");
				if (exclamIndex == -1)
				{
					Nick = nickUser;
					IsGlobal = Nick.ToLower() == "global";
					return;
				}
				Nick = nickUser.Substring(0, exclamIndex);
				User = nickUser.Substring(exclamIndex + 1);
				IsGlobal = Nick.ToLower() == "global";
			}
		}
	}
}
